import {createRouter, createWebHistory} from "vue-router";
import routes from "./routes.js";


const router = createRouter({
    history: createWebHistory(),
    routes,
})

// 在跳转路由之前获取到这三个对象
router.beforeEach((to, from, next) => {
    // 如果将要到达这个路由是login或register 就放行
    if (/^.*(login|register)+$/.test(to.path)) return next()
    const status = localStorage.getItem("status")
    if (/^\/(user|document).*$/ && status === "501") return next("/user/login")
    next()
})
export default router
